import http from '@/utils/http'

const BASE_URL = '/asset/check/task'

export interface CheckTaskResp {
  id: string
  name: string
  type: string
  startDate: string
  endDate: string
  userId: string
  status: string
  createUser: string
  createTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}
export interface CheckTaskDetailResp {
  id: string
  name: string
  type: string
  startDate: string
  endDate: string
  userId: string
  status: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}

export interface CheckItemResp {
  id: string
  taskId: string
  itemId: string
  code: string
  name: string
  sn: string
  status: string
  checkerId: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}
export interface CheckItemDetailResp {
  id: string
  taskId: string
  itemId: string
  code: string
  name: string
  sn: string
  status: string
  checkerId: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}
export interface CheckItemQuery {
  sort: Array<string>
}
export interface CheckItemPageQuery extends CheckItemQuery, PageQuery {}

export interface CheckTaskQuery {
  name: string | undefined
  sort: Array<string>
}
export interface CheckTaskPageQuery extends CheckTaskQuery, PageQuery {}

/** @desc 查询盘点任务列表 */
export function listCheckTask(query: CheckTaskPageQuery) {
  return http.get<PageRes<CheckTaskResp[]>>(BASE_URL, query)
}

/** @desc 查询盘点任务详情 */
export function getCheckTask(id: string) {
  return http.get<CheckTaskDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增盘点任务 */
export function addCheckTask(data: any) {
  return http.post(BASE_URL, data)
}

/** @desc 修改盘点任务 */
export function updateCheckTask(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除盘点任务 */
export function deleteCheckTask(id: string) {
  return http.del(BASE_URL, { ids: [id] })
}

/** @desc 导出盘点任务 */
export function exportCheckTask(query: CheckTaskQuery) {
  return http.download(`${BASE_URL}/export`, query)
}

/** @desc 取消盘点任务 */
export function checkTaskCancel(id: string) {
  return http.get(`${BASE_URL}/cancel/${id}`)
}

/** @desc 查询盘点资产名单列表 */
export function listCheckItem(query: CheckItemPageQuery) {
  return http.get<PageRes<CheckItemResp[]>>(`${BASE_URL}/items`, query)
}

/** @desc 盘点处理 */
export function updateCheckItem(data: any, id: string) {
  return http.put(`${BASE_URL}/items/check/${id}`, data)
}

/** @desc 盘点清单导出 */
export function exportCheckItem(query: CheckItemQuery) {
  return http.download(`${BASE_URL}/items/export`, query)
}

